🏷ī¸ computer-science 🏷ī¸ tech

# Functional Programming

If you find dealing with states in your Object Oriented Programming (OOP) codebase difficult or error-prone, you might want to say goodbye to states, and try functional programming (FP).

Functional Programming is one of the many paradigms of programming.

# FP vs OOP

In OOP paradigm, you think everything in terms of objects (even non-physical entities like concepts and logics) and try to create an universe where those objects interact with each other, changing each other's state over time.

Example: (in Python)

my_object = SomeClass()

for some_object in another_object:
    my_object.change_state(some_obbject)

my_object.print_result()

# As you see, my_object state changes over time, and we, programmers are
# responsible for actually changing state and keeping track of the changes.
copy success

While in FP paradigm, you think everything in terms of functions, i.e. things you encountered back then in mathematics that looked like ƒ, that, when given an input produces some output. There's no concept of time here, and hence no concept of states either.

Example: (in Elm)

myFunction dataProducerFunction =
	dataProducerFunction
	|> List.map someFunciton
	|> anotherFunction
	|> printFunction

{-| As you see, we only define a function, that will produce output when given
    some input data. The input data (a function) doesn't change.
    An outside program will use this function to change state, but we don't
    need to worry about that. In FP, we only define what happens when the data
    comes.
-}
copy success

FP is more closer to mathematics than OOP can ever hope to be, allowing it to reasonably tackle some of the head-scratching limitations OOP comes with.

# Why isn't Functional Programming the norm?

# FP and Mathematics

Mathematics is the basis of FP, but IMO Category Theory defines the most interesting concepts of FP.

Two algebraic data types that define the building blocks of FP that you will encounter in many FP languages are:

# FP languages

Some popular FP languages are:

# Resources

# Functional Programming for Pragmatists â€ĸ Richard Feldman â€ĸ GOTO 2021

# Functional Programming Design Patterns

https://vimeo.com/113588389

# The Functional Programmer's Toolkit


Learn More:


  1. https://news.ycombinator.com/item?id=12056169 ↩ī¸Ž



✏ī¸ Edit this note